
var app = new Vue({
    el: '#center-in-center',
    data: {
        result:null,
        resultList:[],
        musicimage:null,
        like:"img/like.png",
        animationShow:'',
        hotComments:[],
        musicUrl:[],
        singer:null,
        songTitle:null
    },
    methods: {
        find:function(){
            var that = this;
            axios.get("https://autumnfish.cn/search?keywords="+this.result)
                .then(function (response) {  
                    // console.log(response);                  
                    console.log(response.data.result.songs);
                     that.resultList = response.data.result.songs;
                })
                .catch(function (err) { })
        },
        addlike:function(name){
            // 获取点击到的歌曲
            var songName = document.getElementsByClassName("like")[name];
            console.log(songName.src)
            if(songName.src == "img/like.png")
            {
                var r = confirm("确定加入喜欢吗，亲？🙂");
			    if (r){
				songName.src = "img/iLike.png"
			    }else{
                    console.log("确定不加入喜欢")
                }
            }else{
                var f = confirm("确定移除喜欢吗，亲？😢");
			    if (f){
				songName.src = "img/like.png"
			    }else{
                    console.log("确定不移除不喜欢")
                }
            }
        },
            start:function(musicId,name,songName){
            this.singer = name;
            this.songTitle = songName;
            var that = this;
            //播放音乐
			axios.get("https://autumnfish.cn/song/url?id="+musicId)
			.then(function(respontse){
				that.musicUrl=respontse.data.data[0].url;
				//console.log(respontse.data.data[0].url)
			},function(err){console.log(err)});
            // 歌曲封面获取
			axios.get("https://autumnfish.cn/song/detail?ids="+musicId)
			.then(function(respontse){
				that.musicimage=respontse.data.songs[0].al.picUrl;
				// console.log(respontse)
			},function(err){console.log(err)});
            // 歌曲评论获取
            axios.get("https://autumnfish.cn/comment/hot?type=0&id=" + musicId).then(
            function(response) {
            // console.log(response);
            // console.log(response.data.hotComments);
            that.hotComments = response.data.hotComments;
            var timeLength = that.hotComments.length
            // console.log(timeLength)
            try{
                for(var i = 0;i <= timeLength;i++){
                    // var unixTimestamp = new Date(that.hotComments[i].time * 1000) 
                    // var commonTime = unixTimestamp.toLocaleString()
                    // console.log(commonTime)
                    // that.hotComments[i].time = commonTime;
                    var year = new Date(that.hotComments[i].time).getFullYear();
                    var month = new Date(that.hotComments[i].time).getMonth() + 1;
                    var d = new Date(that.hotComments[i].time).getDate();
                    var h = new Date(that.hotComments[i].time).getHours();
                    var m = new Date(that.hotComments[i].time).getMinutes();
                    var s = new Date(that.hotComments[i].time).getSeconds();
                    // console.log(year+'年'+month+'月'+d+'日'+h+'时'+m+'分'+s+'秒')
                    that.hotComments[i].time = year+'年'+month+'月'+d+'日'+h+'时'+m+'分'+s+'秒'
                    }
                }catch{}
            
        },
        function(err) {}
      );
        },
    // 控制封面图旋转
    // 播放
    play: function() {
        // console.log("play");
        this.animationShow="running"
      },
      // 暂停
    pause: function() {
        // console.log("pause");
        this.animationShow="paused"
      }
    }
})